package io.renren.modules.eightapp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.eightapp.dao.EiComplainInfoDao;

import io.renren.modules.eightapp.dto.EiComplainDTO;
import io.renren.modules.eightapp.dto.EiComplainInfoDTO;
import io.renren.modules.eightapp.entity.EiComplainInfoEntity;
import io.renren.modules.eightapp.entity.EiManagerInfoEntity;
import io.renren.modules.eightapp.service.EiComplainInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author Mark 1132115960@gmail.com
 * @since 1.0.0 2022-12-27
 */
@Service
public class EiComplainInfoServiceImpl extends CrudServiceImpl<EiComplainInfoDao, EiComplainInfoEntity, EiComplainInfoDTO> implements EiComplainInfoService {


    @Autowired
    private EiComplainInfoDao eiComplainInfoDao;

    @Override
    public int updateStateById(Integer id) {
        EiComplainInfoEntity eiComplainInfoEntity = new EiComplainInfoEntity();
        eiComplainInfoEntity.setState(1);
        eiComplainInfoEntity.setId(id);
        int i = eiComplainInfoDao.updateById(eiComplainInfoEntity);
        return i;
    }

    @Override
    public List<EiComplainInfoDTO> getComplainListByownerId(int ownerId) {
        QueryWrapper<EiComplainInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().select().eq(EiComplainInfoEntity::getOwnerId,ownerId);
        List<EiComplainInfoEntity> eiComplainInfoEntities = eiComplainInfoDao.selectList(queryWrapper);
        List<EiComplainInfoDTO> list = ConvertUtils.sourceToTarget(eiComplainInfoEntities, EiComplainInfoDTO.class);
        return list;
    }

    @Override
    public EiComplainInfoDTO getComplainById(int id) {
        EiComplainInfoEntity eiComplainInfoEntity = eiComplainInfoDao.selectById(id);
        EiComplainInfoDTO eiComplainInfoDTO = ConvertUtils.sourceToTarget(eiComplainInfoEntity, EiComplainInfoDTO.class);
        return eiComplainInfoDTO;
    }

    @Override
    public Integer deleteComplainById(int id) {
        int i = eiComplainInfoDao.deleteById(id);
        return i;
    }

    @Override
    public Integer deleteComplainList(List<Integer> ids) {
        int i = eiComplainInfoDao.deleteBatchIds(ids);
        return i;
    }

    @Override
    public Integer getStateListById(List<Integer> ids) {
        List<EiComplainInfoEntity> list = eiComplainInfoDao.selectBatchIds(ids);
        for(int i=0;i<list.size();i++) {
            if(list.get(i).getState() == 1) {
                return 1;
            }
        }
        return 0;
    }

    @Override
    public List<EiComplainDTO> getComplainList() {
        List<EiComplainDTO> listAll = eiComplainInfoDao.getComplainList();
        return listAll;
    }

    @Override
    public QueryWrapper<EiComplainInfoEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<EiComplainInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }


}